package tr.edu.yildiz.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.apache.log4j.PropertyConfigurator;

/**
 * General purpose logger for system.
 * 
 * @author Onur Ulusu
 * 
 */
public class LoggerUtils {

	private static final String LOGGER_NAME = "MARKOV";
	private static final String lOG_FILE_PATH = "./conf/log4j.properties";
	public static final Logger logger = Logger.getLogger(LOGGER_NAME);

	/**
	 * Reads configuration file and intitializes logger.
	 * 
	 * @return true if logger is successfuly initialized, else returns false.
	 */
	public static boolean initializeLog4j() {
		Properties logProp = new Properties();
		try {
			// Loading log4j property file.
			logProp.load(new FileInputStream(lOG_FILE_PATH));
			PropertyConfigurator.configure(logProp);
			logger.info("Logger enabled");
			return true;
		} catch (IOException e) {
			logger.info("Logger not enabled, error occurred: " + e.getMessage());
			return false;
		}
	}
}
